<?php
include_once "header.php";


if(isset($_POST['profil_kantor'])){
	if($_POST['provinsi']!="" || $_POST['alamat']!="" || $_POST['kota']!="" ||
		$_POST['telp']!="" || $_POST['faks']!=""){
		
		$daftar_kantor = new Daftar_kantor();
		$kantor = new Kantor();
		$kantor->setKd_kantor($_POST['kd_kantor']);
		$kantor->setKd_provinsi($_POST['provinsi']);
		$kantor->setAlamat($_POST['alamat']);
		$kantor->setKota($_POST['kota']);
		$kantor->setTelp($_POST['telp']);
		$kantor->setFaks($_POST['faks']);
		
		if($daftar_kantor->edit($kantor)==true){
				echo "<script>
						alert('Informasi: Profil berhasil diubah');
						window.location.href='profil_kantor.php';
					</script>";
			} else {
			
				echo "<script>
						alert('Informasi:Profil gagal diubah');
					</script>";
			
				
			}
		
	}

}

$daftar_kantor = new Daftar_kantor();
$kantor=$daftar_kantor->get();

$daftar_provinsi = new Daftar_provinsi();
$provinsi=$daftar_provinsi->getAll();

?>


<div id="container">
	<div id="errorcont">
		<?php //echo $cek_field;
		?>
	</div>
	<div id="maincont">
		<?php include_once "menu_samping.php"; ?>
		<div id="mainright">
			<div id="title">
			Profil Kantor
			</div>
			<div id="body">
			</br>
			<form name="form" method="POST" action="profil_kantor.php">
			<input type="hidden" name="profil_kantor">
			<input type="hidden" name="kd_kantor" value="<?php echo $kantor->getKd_kantor(); ?>">
			<table border=0 cellspacing=0 cellpadding=4 width=100%>		
				<tr>
					<td Width=15%>Provinsi</td>
					<td Width=3%>:</td>
					<td>
					<select  name="provinsi">
						<?php
						if($kantor->getKd_provinsi()=="0"){
								echo "<option value=\"\" selected> -- </option>";
							}
						foreach($provinsi as $P){
							if($kantor->getKd_provinsi()==$P->getKd_provinsi()){
								echo "<option value=".$P->getKd_provinsi()." selected>".$P->getProvinsi()."</option>";
							} 
							
							else {
								echo "<option value=".$P->getKd_provinsi().">".$P->getProvinsi()."</option>";
							}
						}
						
						
						?>
						
					</select>
					</td>
				</tr>
				<tr>
					<td>Alamat</td>
					<td>:</td>
					<td>
					<input type="text" name="alamat" value="<?php echo $kantor->getAlamat();?>" size="96" maxlength="96">
					</td>
				</tr>
				
				<tr>
					<td>Kota</td>
					<td>:</td>
					<td>
					<input type="text" name="kota" value="<?php echo $kantor->getKota(); ?>" size="64" maxlength="64">
					</td>
				</tr>
				
				<tr>
					<td>Telp</td>
					<td>:</td>
					<td>
					<input type="text" name="telp" value="<?php echo $kantor->getTelp(); ?>" size="15" maxlength="15">
					</td>
				</tr>
				<tr>
					<td>Faks</td>
					<td>:</td>
					<td>
					<input type="text" name="faks" value="<?php echo $kantor->getFaks(); ?>" size="15" maxlength="15">
					</td>
				</tr>
				
				<tr>
					<td></td>
					<td></td>
					<td align="right">
					
					<input type="submit" value="Simpan" onClick="return cekField();">
					<input type="reset" value="Batal">
					
					</td>
				</tr>
	
			</table>
			</form>
			<br>
		
			</div>
        </div>
	</div>
</div>
<?php
	include_once "footer.php";
?>

<script type="text/javascript">


function cekField(){
	
		var provinsi = document.forms['form']['provinsi'].value;
		var alamat = document.forms['form']['alamat'].value;
		var kota = document.forms['form']['kota'].value;
		var telp = document.forms['form']['telp'].value;
		var faks = document.forms['form']['faks'].value;
			
		
		if(provinsi=="" || alamat=="" || kota=="" || telp=="" || faks==""){
			alert('Peringatan : Silahkan isikan seluruh data yang tersedia.');
			return false;
		}
		
		if(provinsi!="" && alamat!="" && kota!="" && telp!="" && faks!=""){
			var tanya = confirm('Konfirmasi: Apakah Anda ingin menyimpan perubahan?');
			if(tanya){
				return true;
			}
			 else {
				return false;
			 }
		}
	
}
	
</script>

